package com.ynet.middleground.user.job;

import com.ynet.cache.lock.AquiredLockWorker;
import com.ynet.cache.lock.RedisLocker;
import com.ynet.core.log.IfpLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * redis锁demo
 * 使用时请注意waitTime和lockTime的时间差问题
 * @author yangbh
 */
@Deprecated
@Component
public class TestRedisJob {

    @Autowired
    private RedisLocker redisLocker;

//    @Scheduled(cron = "0/5 * * * * *")
//    @Scheduled(fixedDelay = 1234234)
//    public void test() throws Exception {
//        redisLocker.lock("user:job:test",new AquiredLockWorker<Object>() {
//            @Override
//            public Object invokeAfterLockAquire() {
//                IfpLogger.info("job", "执行测试开始");
//                doTestJob();
//                IfpLogger.info("job", "执行测试结束");
//
//                return null;
//            }
//
//        }, 0, 25);
//    }

    private void doTestJob() {

        try {
            Thread.sleep(20000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        IfpLogger.info("job", "分布式日志输出:{}" , LocalDateTime.now());

    }
}
